package cn.com.elite;

import java.util.List;

import javax.sql.DataSource;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.PlatformTransactionManager;

public class EliteBean1 {
	private static final Log log=LogFactory.getLog(EliteBean1.class);
    private DataSource dataSource;
    private DataSourceTransactionManager tran;
    private PlatformTransactionManager transactionManager;
	public DataSource getDataSource() {
		return dataSource;
	}
	public void setDataSource(DataSource dataSource) {
		this.dataSource = dataSource;
	}
	public DataSourceTransactionManager getTran() {
		return tran;
	}
	public void setTran(DataSourceTransactionManager tran) {
		this.tran = tran;
	}
	public PlatformTransactionManager getTransactionManager() {
		return transactionManager;
	}
	public void setTransactionManager(PlatformTransactionManager transactionManager) {
		this.transactionManager = transactionManager;
	}
	
	public List chaxun(String sql) throws Exception{
		 try{
			 JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
//			 jdbcTemplate.execute(" set names utf8 ");
//			 log.info("list:"+jdbcTemplate.queryForList(" show variables like '%char%' "));
		     List resultList = jdbcTemplate.queryForList(sql);
		     return resultList;
		 }catch(Exception e){
			 log.error("chaxun出错:"+EliteUtil.getERRO(e));  
			 return null;
		 }
	 }
     
	public int update(String sql)throws Exception{
		try{
			 JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
		     int resultList=jdbcTemplate.update(sql);
		     return resultList;
		 }catch(Exception e){
			 log.error("chaxun出错:"+EliteUtil.getERRO(e));  
			 return 0;
		 }
	}
}
